package com.hontech.bv.ui.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.hontech.bv.R
import com.hontech.bv.model.heat.HeatStatus
import com.hontech.bv.model.heat.StatusUpdateEvent
import com.hontech.bv.task.eventBus
import com.hontech.bv.ui.fragment.heat.CtrlDelegate
import com.hontech.bv.ui.fragment.heat.HeatPartsDialog
import com.hontech.bv.ui.fragment.heat.HeatSensor2Dialog
import com.hontech.bv.ui.fragment.heat.HeatSensorDialog
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode

class HeatFragment : Fragment() {


    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        val view = inflater.inflate(R.layout.fragment_heat, null)
        initUi(view)
        return view
    }

    private fun initUi(view: View) {
        CtrlDelegate(view)
    }

    @Subscribe(threadMode = ThreadMode.MAIN_ORDERED)
    fun onStatusUpdateEvent(_env: StatusUpdateEvent) {
        HeatSensorDialog.update(HeatStatus.status)
        HeatSensor2Dialog.update(HeatStatus.status)
        HeatPartsDialog.update(HeatStatus.status.ctrl())
    }

    override fun onStart() {
        super.onStart()
        eventBus.register(this)
    }

    override fun onStop() {
        super.onStop()
        eventBus.unregister(this)
    }
}

